// pages/vacation/vacation.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },
  PickerChange(e) {
    console.log(e);
    this.setData({
      index: e.detail.value
    })
  },
  DateChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  DateChange1(e) {
    this.setData({
      date1: e.detail.value
    })
  },
  forsubmit(e){
    var ename = e.detail.value.ename;
    var empno = e.detail.value.empno;
    var dname = this.data.picker[this.data.index];
    var reason = e.detail.value.reason;
    var startdate = this.data.date;
    var enddate = this.data.date1;
    //Toast提示
    if(ename == ""){
      wx.showToast({
        title: '姓名不能为空',
        icon: 'none'
      })
    } else if (empno == ""){
      wx.showToast({
        title: '工号不能为空',
        icon: 'none'
      })
    }
    else if (reason == ""){
      wx.showToast({
        title: '原因不能为空',
        icon: 'none'
      })
    }else{
      wx.request({
        url: 'http://192.168.1.6:8080/WeChatJSON//insertVacation',
        data: {
          ename:ename,
          empno:empno,
          dname: dname,
          reason: reason,
          startdate: startdate,
          enddate: enddate
        }, method: 'GET',
        header: {
          'content-type': 'application/json'
        },
        success:function(res){
          console.log(res)
          var msg = res.data;
          if (msg === '申请成功'){
            wx.showToast({
            title: msg,
              icon: 'success'
            })
            setTimeout(function () {
              wx.navigateBack({
              })
            }, 1500) 
          }else{
            wx.showToast({
              title: msg,
              icon: 'none'
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var time = new Date();
    var year = time.getFullYear();
    var month = (time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1);
    var day = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
    this.setData({
      nowDate: year + '-' + month + '-' + day,
      date: year + '-' + month + '-' + day,
      date1: year + '-' + month + '-' + day,
    })

    console.log(options)
    if(options.level === 'T3'){
      this.setData({
        dsble: false,
        index: 0,
        picker: [options.dname],
      })
    }else{
      this.setData({
        ename: options.ename,
        empno: options.empno,
        dsble:true,
        picker: [options.dname],
        index:0
      })
    }

  },

})